package org.soarsky.wealthchengdu.google.map;


import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;



/**
 * 
 * @author kongli
 *
 */
public class GoogleMapService extends Service {
	private static final String TAG="GooglMapService";
	public static final String START_LOCATION_LISTENER = "intent.google.START_LOCATION_LISTENER";
	public static final String STOP_LOCATION_LISTENER = "intent.google.STOP_LOCATION_LISTENER";
	public static final String RESTART_GPS_MONITOR = "intent.outdoortracker.restart.gps.monitor";
	public static final String RECORD_TRACK = "intent.outdoortracker.record_track";
	public static final String RESET_ADJUSTDISTANCE = "intent.outdoortracker.RESET_ADJUSTDISTANCE";
	
	public static final String GPS_STATUS_CHANGED = "outdoortracker.intent.action.GPS_STATUS_CHANGED";
	public static final String LOCATION_CHANGED = "outdoortracker.intent.action.LOCATION_CHANGED";
	public static final String SATELLITE_CHANGED = "outdoortracker.intent.action.SATELLITE_CHANGED";
	public static final String SPEED_ISZERO = "outdoortracker.intent.action.SPEED_ISZERO";
	public static final String MARK_CHANGED = "outdoortracker.intent.action.MARK_CHANGED";
	
	//private Map
	private float mAdjustDistance = 0;
	//private RecordManager mRecordManager = null;
	private BaiduLocation mBaiduLocation;
	private void log(String msg){
		Log.d(TAG, msg);
	}
	
	private void logE(String msg){
		Log.d(TAG, msg);
	}
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		log("onCreate");
		//mApp = APP.getInstance();
		//mBaiduLocation = mApp.getBaiduLocation();
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		log("onDestroy");
		super.onDestroy();
	}

	@Override
	public void onStart(Intent intent, int startId) {
		// TODO Auto-generated method stub
		super.onStart(intent, startId);
		if (intent == null) return;
		String action = intent.getAction();
		if (action.equals(START_LOCATION_LISTENER)){
			//log("START_LOCATION_LISTENER");
			Log.e("========", "test111");
			if(GoogleMapActivity.getInstance()!=null&&(mBaiduLocation=GoogleMapActivity.getInstance().getBaiduLocation())!=null){
				Log.e("========", "test");
				mBaiduLocation.startLocation(false,1);
			}
			log("START_LOCATION_LISTENER"+" "+GoogleMapActivity.getInstance()+GoogleMapActivity.getInstance().getBaiduLocation());
			//mRecordManager.startLocationListener();
		}else if (action.equals(STOP_LOCATION_LISTENER)){
			if(GoogleMapActivity.getInstance()!=null&&(mBaiduLocation=GoogleMapActivity.getInstance().getBaiduLocation())!=null){
				mBaiduLocation.stopLocation(false);
			}
 			//log("STOP_LOCATION_LISTENER"+" "+GoogleMapActivity.getInstance()+GoogleMapActivity.getInstance().getBaiduLocation());
 			 
		}else if (action.equals(RESTART_GPS_MONITOR)){
			log("RESTART_GPS_MONITOR");
		}
	}

	public static void startService(Context context,String action){
		Intent intent = new Intent(action);
		intent.setClass(context, GoogleMapService.class);
		context.startService(intent);
	}
	
}
